package model

import (
	"gpt-api/framework/db"
)

type UserVideo struct {
	db.BaseModel
	UserId   uint   `json:"user_id" gorm:"column:user_id;type:int;default:0;comment:用户ID"`
	VideoUrl string `json:"video_url" gorm:"column:video_url;type:varchar(255);default:'';comment:视频地址"`
}

func (UserVideo) TableName() string {
	return "user_video"
}

// 根据用户ID查询视频列表
func (u UserVideo) GetVideosByUserId(database *db.DB, userId uint64) ([]UserVideo, error) {
	var userVideos []UserVideo
	err := database.Model(&UserVideo{}).Where("user_id = ?", userId).Find(&userVideos).Error
	return userVideos, err
}

// 创建用户视频
func (u *UserVideo) Create(database *db.DB) error {
	return database.Create(u).Error
}

func (u *UserVideo) GetVideoByUserIdAndPath(database *db.DB, userId uint64, path string) (UserVideo, error) {
	var userVideo UserVideo
	err := database.Model(&UserVideo{}).Where("user_id = ? and video_url = ?", userId, path).First(&userVideo).Error
	return userVideo, err
}
